<template>
	<view>
		<view class="usercard">
			<view class="avatar">
				<image src="/static/icon/my.png" mode="widthFix" style="width:160upx; height:160upx;"></image>
			</view>
			<view class="nickname">{{info.name}}</view>
		</view>
		<view class="actionList">
			<view v-if="shenfen==1">
			<view class="alistItem" @tap="needLoginToNav('/pages/my/changeInfo')">
				<view class="label" >修改资料</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="alistItem" @tap="needLoginToNav('/pages/my/changePwd')">
				<view class="label">修改密码</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="alistItem" @tap="needLoginToNav('/pages/my/personList')">
				<view class="label">管理员工</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			</view>
			<view class="alistItem" @tap="exit">
				<view class="label">退出登录</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="xidi">
		<image :src="cdnUrl+'/logo.png'" class="llogo"></image>
		</view>
	</view>
</template>

<script>
import jsrsasign from 'jsrsasign';
import helper from '../../common/helper';
import api from '@/api.js';
	
	export default {
		mixins:[helper],
		data() {
			return {
				info:{},
				shenfen:2,
			}
		},
		onLoad(e){
			if(!uni.getStorageSync('ctoken')){
				uni.navigateTo({
					url:'/pages/login/login'
				})
			}else{
				var json=this.decodeJWT(uni.getStorageSync('ctoken'));
				console.log(json);
				if(json.shenfen==2){
					this.shenfen=2;
				}else{
					this.shenfen=1;
				}
			}
			api.doRequest('get','my/info').then(res=>{
				if(res.statusCode==200){
					this.info=res.data.data;
				}
			})
		},
		methods: {
			decodeJWT(token){
				let obj = null
					if (token !== '') {
						const payload = jsrsasign.KJUR.jws.JWS.parse(token)
						if (payload.hasOwnProperty('payloadObj')) {
							obj = payload.payloadObj
						}
					}
				return obj
				
			},
			// decodeJwt(token) {
			//     var base64Url = token.split('.')[1];
		
			//     var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
			//     var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
			//         return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
			//     }).join(''));
			 
			//     return JSON.parse(jsonPayload);
			// },
			exit(){
				uni.setStorageSync('ctoken','');
				uni.redirectTo({
					url:'/pages/login/login'
				})
			}
		}
	}
</script>

<style>
	.usercard{
		width:710upx; background:#004ea2;height:400upx;
		padding:20upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.nickname{color:#fff;line-height:80upx;}
	.alistItem{
		width:710upx;
		padding:0 20upx;
		height:80upx;
		border-bottom:1upx solid #ccc;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.avatar{
		width:200upx; height:200upx;background:#fff;display: flex;align-items: center;justify-content: center;
		border-radius:100upx;
	}
	.llogo{width:40upx; height:40upx;display: block;margin:20upx auto;margin-bottom:100upx;}
</style>
